#include<bits/stdc++.h>
using namespace std;
int T;
int ans;
int main(){
    freopen("color1.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        int n=0;
        cin>>n;
        int a[n+5];
        for(int i=1;i<=n;i++)cin>>a[i];
        if(n==3){
            ans=1;
            cout<<ans<<endl;
        }
        if(n==4){
            ans=0;
            cout<<ans<<endl;
        }
        if(n==8){
            ans=8;
            cout<<ans<<endl;
        }
    }
    return 0;
}
